/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyecto.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import proyecto.dao.PacienteDao;
import proyecto.modelo.Paciente;

/**
 *
 * @author rvertiz
 */
public class PacienteController extends MultiActionController {

    public PacienteController() {
        //Initialize controller properties here or
        //in the Web Application Context
        //setCommandClass(MyCommand.class);
        //setCommandName("MyCommandName");
        //setSuccessView("successView");
        //setFormView("formView");
    }

    //@Override
    protected void doSubmitAction(Object command) throws Exception {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private PacienteDao pacienteDao;

    public PacienteDao getPacienteDao() {
        return pacienteDao;
    }

    public void setPacienteDao(PacienteDao pacienteDao) {
        this.pacienteDao = pacienteDao;
    }

    public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
        return new ModelAndView("pacientes");
    }

        public ModelAndView insertarPaciente(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("Entro a la llamada a insertar paciente");
            return new ModelAndView("pacientes");
    }

     public ModelAndView doInsertarPaciente(HttpServletRequest request, HttpServletResponse response) {
        //Usuario vo = new Usuario();
        //SimpleDateFormat df=new SimpleDateFormat("dd/mm/yyyy");
        Paciente P = new Paciente();
        P.setId_paciente(Integer.parseInt(request.getParameter("CodPaciente")));
        P.setNombres(request.getParameter("nomPaciente"));
        P.setApellidos(request.getParameter("apPaciente"));
        P.setSexo(request.getParameter("Sexo"));
        P.setFec_nacimiento(request.getParameter("FecNac"));
        P.setTipo_documento(request.getParameter("TipoDoc"));
        P.setNumero_documento(request.getParameter("NumDoc"));
        P.setEmail(request.getParameter("Email"));
        P.setTelefono(request.getParameter("Telefono"));
        P.setLogin(request.getParameter("Login"));
        P.setPassword(request.getParameter("Pass"));
        System.out.println("Creo todo Paciente");
        pacienteDao.insertarPaciente(P);

        ModelAndView mv = new ModelAndView("pacientes");
        mv.addObject("pacientes", pacienteDao.listarPaciente());
        return mv;
    }
}
